package task3to18USB;

import java.util.ArrayList;

public class Computer {

    //一种方式：分别定义3个子类属性；
    //另一种方：数组
    USB[] usbs = new USB[3];


    public void on() {
        for (int i = 0; i < usbs.length; i++) {
            usbs[i].open();
        }
        System.out.println("计算机开机成功");
    }

    public void off() {
        for (int i = 0; i < usbs.length; i++) {
            usbs[i].close();
        }
        System.out.println("计算机关机成功");
    }

    public void add(USB usb) {
        for (int i = 0; i < usbs.length; i++) {
            if (usbs[i] == null) {
                usbs[i] = usb;
                break;
            }

        }
    }


}
